<template>
<div class="layerRtb layerRtb-threecolumn">
    <three-title :title="{name:'发起整改'}"></three-title>
    <div class="layerRtb-scroll thinScroll" v-scrollHeight = "137">
        <div class="analyItem">
            <p class="analyItemTit tx-center">项目</p>
            <div class="analyItemCon">
                <p class="col-md-4">
                    <span class="cLightGray pr8">单号</span>
                    <span>{{leftInfo.orderno}}</span>
                </p>
                <p class="col-md-8">
                    <span class="cLightGray pr8">项目名称</span>
                    <span>{{leftInfo.proname}}</span>
                </p>
            </div>
        </div>
        <div class="analyItem">
            <p class="analyItemTit tx-center">整改内容</p>
            <div class="analyItemCon">
                <p class="col-md-6">
                    <span class="cLightGray pr8 fl">罚款类型</span>
                    <el-select v-model="typeValue" placeholder="请选择类型" @change="typeChange()" class="fl" style="width: 150px">
                        <el-option
                            size="mini"
                            v-for="item in typeOptions"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </p>
                <p class="col-md-6">
                    <span class="cLightGray pr8 fl">罚款科目</span>
                    <el-select v-model="projectValue" placeholder="请选择科目" @change="projectChange()"  class="fl"  style="width: 150px">
                        <el-option
                            size="mini"
                            v-for="item in projectOptions"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </p>
                <p class="col-md-6 mt10">
                    <span class="cLightGray pr8 fl">罚款等级</span>
                    <el-select v-model="gradeValue" placeholder="请选择等级" @change="GradeChange()"  class="fl" style="width: 150px">
                        <el-option
                            size="mini"
                            v-for="item in gradeList"
                            :key="item.id"
                            :label="item.gradeLabel"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </p>
                <p class="col-md-6 mt10">
                    <span class="cLightGray pr8 fl">罚款金额</span>
                    <span>{{currentGrade === null ? '' : currentGrade.fine}}</span>
                </p>
                <p class="col-md-6 mt10">
                    <span class="cLightGray pr8 fl">结束时间</span>
                    <el-date-picker
                        style="width: 150px"
                        :picker-options="pickerBeginDateBefore"
                        v-model="endtime"
                        type="date"
                        placeholder="选择结束日期">
                    </el-date-picker>
                </p>
                <p class="col-md-6 mt10">
                    <span class="cLightGray pr8 fl">积分</span>
                    <span>{{currentGrade === null ? '' : currentGrade.integral}}</span>
                </p>
                <p class="col-md-12 mt10">
                    <span class="cLightGray pr8 fl">问题描述</span>
                    <textarea v-model="changeTextDec" placeholder="请描述内容" class="col-md-10"></textarea>
                </p>
                <!-- <p class="col-md-6">
                    <span class="cLightGray pr8 fl">罚款金额</span>
                    <el-input v-model="moneyInput" placeholder="请输入罚款金额" size="mini" class="fl" type="number" style="width:150px"></el-input>
                </p>
                <p class="col-md-6">
                    <span class="cLightGray pr8 fl">结束时间</span>
                    <el-date-picker
                        :picker-options="pickerBeginDateBefore"
                        v-model="endtime"
                        type="date"
                        placeholder="选择结束日期">
                    </el-date-picker>
                </p>
                <p class="col-md-12 mt10">
                    <span class="cLightGray pr8 fl">问题描述</span>
                    <textarea v-model="changeTextDec" placeholder="请描述整改内容" class="col-md-10"></textarea>
                </p> -->
                <div class="col-md-12 mt10">
                    <span class="cLightGray pr8 fl">图片上传</span>
                    <rx-upload
                        class="fl"
                        :data="{id: 11}" :init="{class: 7, mime: 1}"
                        :elStyle="{width:'90px', height: '80px'}"
                        @success="successUpload">
                        <div class="fl uiImgUpload uiImgUpload-gblock mr10">
                            <a href="javascript:">
                                <span type="file" value="" class="file"></span>
                                <em class="bgIcon file-ico"></em>
                            </a>
                        </div>
                    </rx-upload>
                    <rx-viewer v-for="(item, index) of changeList" :key="index" class="mr10 fl">
                        <div class="look_imgHover fl relative" style="width:78px;height:78px;" >
                            <img :src="item">
                            <div class="upload_finish_div">
                                <div class="upload_finish_bg"></div>
                                <div class="upload_finish_linksm">
                                    <div class="dis-il-block">
                                        <a href="javascript:" class="ImgBtn enlarge_viewer enlarge_link" :data-src="item"></a>
                                        <a href="javascript:" class="ImgBtn delect_link" @click="delectImg(index)"></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </rx-viewer>
                </div>
            </div>
        </div>
    </div>
    <div class="layerRtb-footer">
        <div class="analyItem">
            <p class="analyItemTit tx-center">综合</p>
            <div class="analyItemCon">
                <div class="tx-center">
                    <input type="button" class="uiBtn-normal uiBtn-blue" value="确定" @click="saveRectifyOrder()">
                </div>
            </div>
        </div>
    </div>
</div>
</template>
<script>
import { mapGetters, mapMutations } from 'vuex'
import { saveRectifyOrder, getFirstType, getChildStandard, getFineStandardById } from '../../Resources/Api/index'
export default {
    data () {
        return {
            pickerBeginDateBefore: {
                disabledDate: (time) => {
                    return time.getTime() < Date.now() - 8.64e7// 如果没有后面的-8.64e7就是不可以选择今天的
                }
            },
            typeOptions: [], // 类型数组
            projectOptions: [], // 科目数组
            typeValue: '', // 类型Value
            projectValue: '', // 科目Value
            gradeValue: '', // 等级Value
            currentGrade: null, // 当前等级的Value
            gradeList: [], // 等级List
            changeList: [], // 整改图片
            // moneyInput: '', // 整改金额
            changeTextDec: '', // 整改描述
            endtime: '' // 结束时间
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'userInfo'])
    },
    created () {
        this.getFirstType()
    },
    methods: {
        ...mapMutations({
            setUpDatePlate: `SET_UPDATE_PLATE`
        }),
        // 路由跳转路径拼接
        routerPath (path) {
            return this.$route.matched[1].path + '/' + path
        },
        // 直接进行路由跳转路径
        routerPush (path) {
            this.$router.push(this.$route.matched[1].path + '/' + path)
        },
        // 图片上传
        successUpload (value) {
            this.changeList.push(value.src)
        },
        // 删除图片
        delectImg (index) {
            this.changeList.splice(index, 1)
        },
        // 排序
        compare (prop) {
            return function (a, b) {
                return a[prop] - b[prop]
            }
        },
        // 获取类型列表
        getFirstType () {
            getFirstType().then(results => {
                if (results.data.StatusCode === 1) {
                    this.typeOptions = []
                    this.typeOptions = results.data.Body.firstTypeList
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 类型改变获取科目
        typeChange () {
            let parms = {
                id: Number(this.typeValue)
            }
            getChildStandard(parms).then(results => {
                if (results.data.StatusCode === 1) {
                    this.projectOptions = []
                    this.projectOptions = results.data.Body.standardList
                    this.gradeList = []
                    this.projectValue = ''
                    this.gradeValue = ''
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 科目改变获取等级
        projectChange () {
            let parms = {
                id: Number(this.projectValue)
            }
            getFineStandardById(parms).then(results => {
                if (results.data.StatusCode === 1) {
                    this.gradeList = []
                    this.gradeValue = ''
                    this.gradeList = results.data.Body.standardList
                    this.gradeList = this.gradeList.sort(this.compare('grade'))
                    this.gradeList.forEach(item => {
                        switch (Number(item.grade)) {
                        case 1:
                            this.$set(item, 'gradeLabel', '等级一')
                            break
                        case 2:
                            this.$set(item, 'gradeLabel', '等级二')
                            break
                        case 3:
                            this.$set(item, 'gradeLabel', '等级三')
                            break
                        default:
                            break
                        }
                    })
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 等级改变获取罚款
        GradeChange () {
            const currentGrade = this.gradeList.filter((item) => { return item.id === Number(this.gradeValue) })
            if (currentGrade.length > 0) {
                this.currentGrade = currentGrade[0]
                this.changeTextDec = this.currentGrade.remark
                this.endtime = Number(new Date().getTime()) + Number(24 * 60 * 60 * 1000 * Number(this.currentGrade.day))
            }
        },
        // 提交罚款
        saveRectifyOrder () {
            if (this.changeTextDec === '') {
                this.$message('输入整改问题描述')
                return false
            }
            if (this.endtime === '') {
                this.$message('必须选择结束时间')
                return false
            }
            let parmObject = {
                orderNo: this.leftInfo.orderno,
                money: this.currentGrade === null ? 0 : this.currentGrade.fine,
                content: this.changeTextDec,
                standard_id: Number(this.gradeValue),
                img: '',
                endTime: this.endtime,
                createUserNo: this.userInfo.as_cardNo,
                createUserName: this.userInfo.as_fullName
            }
            let parm = {
                rectify: parmObject,
                photoList: this.changeList
            }
            saveRectifyOrder(parm).then((result) => {
                if (result.data.StatusCode === 1) {
                    this.changeList = [] // 整改图片
                    // this.moneyInput = '' // 整改金额
                    this.changeTextDec = '' // 整改描述
                    this.endtime = '' // 结束时间
                    this.fineTextDec = '' // 罚款描述
                    this.typeValue = '' // 类型Value
                    this.projectValue = '' // 科目Value
                    this.gradeValue = '' // 等级Value
                    this.currentGrade = null
                    this.$message('发起整改成功')
                    this.setUpDatePlate()
                } else {
                    this.$message(result.data.statusMsg)
                }
            }).catch((error) => {
                console.log(error)
            })
        }
    }
}
</script>
